package com.huaxin.hxmoduleworkorder.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.huaxin.hxmoduleworkorder.common.enums.base.BaseCodeEnum;

/**
 * 客户类型枚举
 */
public enum CustomerType implements BaseCodeEnum {
    COMMERCIAL("commercial", "商业"),
    //    INDUSTRIAL("industrial", "工业"),
    RESIDENTIAL("residential", "住宅");

    @EnumValue
    private final String code;
    private final String displayName;

    CustomerType(String code, String displayName) {
        this.code = code;
        this.displayName = displayName;
    }

    @JsonValue
    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDisplayName() {
        return displayName;
    }

    public static CustomerType of(String code) {
        for (CustomerType type : values()) {
            if (type.getCode().equalsIgnoreCase(code)) {
                return type;
            }
        }
        return null;
    }

    public static boolean isValid(String code) {
        return of(code) != null;
    }
}
